<div class="content-section introduction">
    <div class="feature-intro">
        <h1>ConfirmDialog</h1>
        <p>ConfirmDialog is backed by a service utilizing Observables to display confirmation windows
            easily that can be shared by multiple actions on the same component.</p>
    </div>
</div>

<div class="content-section implementation">
    <div class="card">
        <h5>Basic</h5>
        <p-confirmDialog [style]="{width: '50vw'}" [baseZIndex]="10000"></p-confirmDialog>
        <p-button (click)="confirm1()" icon="pi pi-check" label="Confirm"></p-button>
        <p-button (click)="confirm2()" icon="pi pi-times" label="Delete"></p-button>
    
        <h5>Position</h5>
        <div class="p-grid p-dir-col">
            <div class="p-col">
                <p-button (click)="confirmPosition('left')" icon="pi pi-arrow-right" label="Left" styleClass="p-button-warning"></p-button>
                <p-button (click)="confirmPosition('right')" icon="pi pi-arrow-left" label="Right" styleClass="p-button-warning"></p-button>
            </div>
            <div class="p-col">
                <p-button (click)="confirmPosition('topleft')" icon="pi pi-arrow-down" label="TopLeft" styleClass="p-button-warning"></p-button>
                <p-button (click)="confirmPosition('top')" icon="pi pi-arrow-down" label="Top" styleClass="p-button-warning"></p-button>
                <p-button (click)="confirmPosition('topright')" icon="pi pi-arrow-down" label="TopRight" styleClass="p-button-warning"></p-button>
            </div>
            <div class="p-col">
                <p-button (click)="confirmPosition('bottomleft')" icon="pi pi-arrow-up" label="BottomLeft" styleClass="p-button-warning"></p-button>
                <p-button (click)="confirmPosition('bottom')" icon="pi pi-arrow-up" label="Bottom" styleClass="p-button-warning"></p-button>
                <p-button (click)="confirmPosition('bottomright')" icon="pi pi-arrow-up" label="BottomRight" styleClass="p-button-warning"></p-button>
            </div>
        </div>
        <p-confirmDialog [style]="{width: '50vw'}" key="positionDialog" [position]="position" [baseZIndex]="10000"></p-confirmDialog>
    </div>

    <p-messages [value]="msgs"></p-messages>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Documentation">
            <h5>Import</h5>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;ConfirmDialogModule&#125; from 'primeng/confirmdialog';
import &#123;ConfirmationService&#125; from 'primeng/api';
</app-code>

            <h5>Getting Started</h5>
            <p>ConfirmDialog is defined using p-confirmDialog tag and an instance of ConfirmationService is required to display it by
                calling confirm method.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"&gt;&lt;/p-confirmDialog&gt;

&lt;button type="text" (click)="confirm()" pButton icon="pi pi-check" label="Confirm"&gt;&lt;/button&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class ConfirmDialogDemo &#123;

    constructor(private confirmationService: ConfirmationService) &#123;&#125;

    confirm() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Are you sure that you want to perform this action?',
            accept: () => &#123;
                //Actual logic to perform a confirmation
            &#125;
        &#125;);
    &#125;
&#125;
</app-code>

            <p>Confirm method takes a confirmation instance used to customize the dialog UI along with accept and reject actions.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>message</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Message of the confirmation.</td>
                        </tr>
                        <tr>
                            <td>key</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Optional key to match the key of the confirm dialog, necessary to use when component tree has multiple confirm dialogs.</td>
                        </tr>
                        <tr>
                            <td>icon</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Icon to display next to the message.</td>
                        </tr>
                        <tr>
                            <td>header</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Header text of the dialog.</td>
                        </tr>
                        <tr>
                            <td>accept</td>
                            <td>Function</td>
                            <td>null</td>
                            <td>Callback to execute when action is confirmed.</td>
                        </tr>
                        <tr>
                            <td>reject</td>
                            <td>Function</td>
                            <td>null</td>
                            <td>Callback to execute when action is rejected.</td>
                        </tr>
                        <tr>
                            <td>acceptLabel</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Label of the accept button.</td>
                        </tr>
                        <tr>
                            <td>rejectLabel</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Label of the reject button.</td>
                        </tr>
                        <tr>
                            <td>acceptIcon</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Icon of the accept button.</td>
                        </tr>
                        <tr>
                            <td>rejectIcon</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Icon of the reject button.</td>
                        </tr>
                        <tr>
                            <td>acceptButtonStyleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the accept button.</td>
                        </tr>
                        <tr>
                            <td>rejectButtonStyleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the reject button.</td>
                        </tr>
                        <tr>
                            <td>acceptVisible</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Visibility of the accept button.</td>
                        </tr>
                        <tr>
                            <td>rejectVisible</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Visibility of the reject button.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                        <tr>
                            <td>maskStyleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the mask.</td>
                        </tr>
                        <tr>
                            <td>blockScroll</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether background scroll should be blocked when dialog is visible.</td>
                        </tr>
                        <tr>
                            <td>defaultFocus</td>
                            <td>string</td>
                            <td>accept</td>
                            <td>Element to receive the focus when the dialog gets visible, valid values are "accept", "reject", "close" and "none".</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>ConfirmationService</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Parameters</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>confirm</td>
                            <td>confirm: Confirmation Object</td>
                            <td>Displays the dialog using the confirmation object options.</td>
                        </tr>
                        <tr>
                            <td>close</td>
                            <td>-</td>
                            <td>Hides the dialog without invoking accept or reject callbacks.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Customization</h5>
            <p>Properties of the dialog are defined in two ways, message, icon and header properties can either
            be defined using confirm method or declaratively on p-confirmDialog ng-template. If these values are unlikely to change then
            declarative approach would be useful, still properties defined in a ng-template can be overriden with confirm method call.</p>

            <p>In addition, buttons at footer section can be customized by passing your own UI, important note to make confirmation work with
            a custom UI is defining a local ng-template variable for the dialog and assign accept()-reject() methods to your own buttons.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-confirmDialog #cd header="Confirmation" icon="pi pi-exclamation-triangle"&gt;
    &lt;p-footer&gt;
        &lt;button type="button" pButton icon="pi pi-times" label="No" (click)="cd.reject()"&gt;&lt;/button&gt;
        &lt;button type="button" pButton icon="pi pi-check" label="Yes" (click)="cd.accept()"&gt;&lt;/button&gt;
    &lt;/p-footer&gt;
&lt;/p-confirmDialog&gt;
</app-code>

            <h5>Animation Configuration</h5>
            <p>Transition of the ConfirmDialog open and hide animations can be customized using the transitionOptions property with a default value as <b>400ms cubic-bezier(0.25, 0.8, 0.25, 1)</b>,
                example below disables the animation altogether.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-confirmDialog [transitionOptions]="'0ms'"&gt;
&lt;/p-confirmDialog&gt;
</app-code>
            <h5>Properties</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                         <tr>
                            <td>header</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Title text of the dialog.</td>
                         </tr>
                         <tr>
                           <td>message</td>
                           <td>string</td>
                           <td>null</td>
                           <td>Message of the confirmation.</td>
                        </tr>
                        <tr>
                            <td>key</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Optional key to match the key of confirm object, necessary to use when component tree has multiple confirm dialogs.</td>
                        </tr>
                        <tr>
                          <td>icon</td>
                          <td>string</td>
                          <td>null</td>
                          <td>Icon to display next to message.</td>
                        </tr>
                        <tr>
                          <td>acceptLabel</td>
                          <td>string</td>
                          <td>Yes</td>
                          <td>Label of the accept button.</td>
                        </tr>
                        <tr>
                          <td>acceptIcon</td>
                          <td>string</td>
                          <td>pi pi-check</td>
                          <td>Icon of the accept button.</td>
                        </tr>
                        <tr>
                          <td>acceptVisible</td>
                          <td>boolean</td>
                          <td>true</td>
                          <td>Visibility of the accept button.</td>
                        </tr>
                        <tr>
                          <td>rejectLabel</td>
                          <td>string</td>
                          <td>No</td>
                          <td>Label of the reject button.</td>
                        </tr>
                        <tr>
                          <td>rejectIcon</td>
                          <td>string</td>
                          <td>pi pi-times</td>
                          <td>Icon of the reject button.</td>
                        </tr>
                        <tr>
                          <td>rejectVisible</td>
                          <td>boolean</td>
                          <td>true</td>
                          <td>Visibility of the reject button.</td>
                        </tr>
                        <tr>
                            <td>closeOnEscape</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Specifies if pressing escape key should hide the dialog.</td>
                        </tr>
                        <tr>
                            <td>rtl</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When enabled dialog is displayed in RTL direction.</td>
                        </tr>
                        <tr>
                            <td>closable</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Adds a close icon to the header to hide the dialog.</td>
                        </tr>
                        <tr>
                            <td>focusTrap</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>When enabled, can only focus on elements inside the confirm dialog.</td>
                        </tr>
                        <tr>
                            <td>appendTo</td>
                            <td>any</td>
                            <td>null</td>
                            <td>Target element to attach the dialog, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).</td>
                        </tr>
                        <tr>
                            <td>acceptButtonStyleClass</td>
                            <td>string</td>
                            <td>p-confirmdialog-acceptbutton</td>
                            <td>Style class of the accept button.</td>
                        </tr>
                        <tr>
                            <td>rejectButtonStyleClass</td>
                            <td>string</td>
                            <td>p-confirmdialog-rejectbutton</td>
                            <td>Style class of the reject button.</td>
                        </tr>
                        <tr>
                            <td>baseZIndex</td>
                            <td>number</td>
                            <td>0</td>
                            <td>Base zIndex value to use in layering.</td>
                        </tr>
                        <tr>
                            <td>autoZIndex</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether to automatically manage layering.</td>
                        </tr>
                        <tr>
                            <td>transitionOptions</td>
                            <td>string</td>
                            <td>400ms cubic-bezier(0.25, 0.8, 0.25, 1)</td>
                            <td>Transition options of the animation.</td>
                        </tr>
                        <tr>
                            <td>defaultFocus</td>
                            <td>string</td>
                            <td>accept</td>
                            <td>Element to receive the focus when the dialog gets visible, valid values are "accept", "reject", "close" and "none".</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Styling</h5>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>p-dialog</td>
                            <td>Container element</td>
                        </tr>
                        <tr>
                            <td>p-confirmdialog</td>
                            <td>Container element</td>
                        </tr>
                        <tr>
                            <td>p-dialog-titlebar</td>
                            <td>Container of header.</td>
                        </tr>
                        <tr>
                            <td>p-dialog-title</td>
                            <td>Header element.</td>
                        </tr>
                        <tr>
                            <td>p-dialog-titlebar-icon</td>
                            <td>Icon container inside header.</td>
                        </tr>
                        <tr>
                            <td>p-dialog-titlebar-close</td>
                            <td>Close icon element.</td>
                        </tr>
                        <tr>
                            <td>p-dialog-content</td>
                            <td>Content element.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Dependencies</h5>
            <p>ConfirmationService</p>
        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/confirmdialog" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-confirmdialog-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;h5&gt;Position&lt;/h5&gt;
&lt;p-confirmDialog [style]="&#123;width: '50vw'&#125;" [baseZIndex]="10000"&gt;&lt;/p-confirmDialog&gt;
&lt;p-button (click)="confirm1()" icon="pi pi-check" label="Confirm"&gt;&lt;/p-button&gt;
&lt;p-button (click)="confirm2()" icon="pi pi-times" label="Delete"&gt;&lt;/p-button&gt;

&lt;h5&gt;Position&lt;/h5&gt;
&lt;div class="p-grid p-dir-col"&gt;
    &lt;div class="p-col"&gt;
        &lt;p-button (click)="confirmPosition('left')" icon="pi pi-arrow-right" label="Left" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
        &lt;p-button (click)="confirmPosition('right')" icon="pi pi-arrow-left" label="Right" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
    &lt;/div&gt;
    &lt;div class="p-col"&gt;
        &lt;p-button (click)="confirmPosition('topleft')" icon="pi pi-arrow-down" label="TopLeft" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
        &lt;p-button (click)="confirmPosition('top')" icon="pi pi-arrow-down" label="Top" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
        &lt;p-button (click)="confirmPosition('topright')" icon="pi pi-arrow-down" label="TopRight" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
    &lt;/div&gt;
    &lt;div class="p-col"&gt;
        &lt;p-button (click)="confirmPosition('bottomleft')" icon="pi pi-arrow-up" label="BottomLeft" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
        &lt;p-button (click)="confirmPosition('bottom')" icon="pi pi-arrow-up" label="Bottom" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
        &lt;p-button (click)="confirmPosition('bottomright')" icon="pi pi-arrow-up" label="BottomRight" styleClass="p-button-warning"&gt;&lt;/p-button&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;p-confirmDialog [style]="&#123;width: '50vw'&#125;" key="positionDialog" [position]="position" [baseZIndex]="10000"&gt;&lt;/p-confirmDialog&gt;


&lt;p-messages [value]="msgs"&gt;&lt;/p-messages&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
@Component(&#123;
    templateUrl: './confirmdialogdemo.html',
    styles: [`
        :host ::ng-deep button &#123;
            margin-right: .25em;
        &#125;
    `],
    providers: [ConfirmationService]
&#125;)
export class ConfirmDialogDemo &#123;

    msgs: Message[] = [];

    position: string;

    constructor(private confirmationService: ConfirmationService) &#123;&#125;

    confirm1() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Are you sure that you want to proceed?',
            header: 'Confirmation',
            icon: 'pi pi-exclamation-triangle',
            accept: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Confirmed', detail:'You have accepted'&#125;];
            &#125;,
            reject: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Rejected', detail:'You have rejected'&#125;];
            &#125;
        &#125;);
    &#125;

    confirm2() &#123;
        this.confirmationService.confirm(&#123;
            message: 'Do you want to delete this record?',
            header: 'Delete Confirmation',
            icon: 'pi pi-info-circle',
            accept: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Confirmed', detail:'Record deleted'&#125;];
            &#125;,
            reject: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Rejected', detail:'You have rejected'&#125;];
            &#125;
        &#125;);
    &#125;

    confirmPosition(position: string) &#123;
        this.position = position;

        this.confirmationService.confirm(&#123;
            message: 'Do you want to delete this record?',
            header: 'Delete Confirmation',
            icon: 'pi pi-info-circle',
            accept: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Confirmed', detail:'Record deleted'&#125;];
            &#125;,
            reject: () => &#123;
                this.msgs = [&#123;severity:'info', summary:'Rejected', detail:'You have rejected'&#125;];
            &#125;,
            key: "positionDialog"
        &#125;);
    &#125;
&#125;
</app-code>
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-confirmdialog-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>
